#include <linux/module.h>
#include <linux/init.h>
#include <linux/input.h>
#include <linux/device.h>



struct input_dev *my_mouse_dev; 

static int __init mymouse_init(void){
    int ret;
    my_mouse_dev = input_allocate_device();
    my_mouse_dev->name="myMouse";
    my_mouse_dev->id.bustype = BUS_USB;
    my_mouse_dev->id.vendor = 0x1111;
    my_mouse_dev->id.product = 0x2222;
    my_mouse_dev->id.version = 0x0001;
    my_mouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
    my_mouse_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE);
    my_mouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); 
    ret = input_register_device(my_mouse_dev);
    if(ret){
        printk("input_register_device fail\n");
        goto fail;
        return ret;
    }
    printk("input_register_device success\n");
    return 0;
fail:
    input_put_device(my_mouse_dev);
    return ret;
}

static void __exit mymouse_exit(void){
    input_free_device(my_mouse_dev);
    input_unregister_device(my_mouse_dev);
    printk("input_unregister_device success\n");
}

MODULE_AUTHOR("WLZ");
MODULE_LICENSE("GPL");
module_init(mymouse_init);
module_exit(mymouse_exit);